﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class promotion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddata();
        }
    }

    private void binddata()
    {
        IList<Promotion> promotionList = PromotionService.GetInstance().GetOrderedPromotionList();
        GridView1.DataSource = promotionList;
        GridView1.DataBind();

        int inprocess = 0;
        int notstart = 0;
        int comingsoon = 0;
        foreach (Promotion promotion in promotionList)
        {
            if (promotion.PromotionStatus == "inprocess" && (promotion.DueDay - DateTime.Now).Days <= 3)
                comingsoon++;
            else if (promotion.PromotionStatus == "inprocess")
                inprocess++;
            else if (promotion.PromotionStatus == "notstart")
                notstart++;
        }

        string statusmessage = "目前没有活动，敬请关注";
        if (comingsoon > 0)
            statusmessage = String.Format("有{0}项活动即将过期", comingsoon);
        else if(inprocess > 0)
            statusmessage = String.Format("有{0}项活动正在进行", inprocess);
        else if (notstart > 0)
            statusmessage = String.Format("有{0}项活动即将开始", notstart);
        spanstatusmsg.InnerText = statusmessage;

        if (this.GridView1.BottomPagerRow != null) (this.GridView1.BottomPagerRow.FindControl("AspNetPager1") as Wuqi.Webdiyer.AspNetPager).RecordCount = promotionList.Count;
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex - 1;
        binddata();
        Wuqi.Webdiyer.AspNetPager pager = this.GridView1.BottomPagerRow.FindControl("AspNetPager1") as Wuqi.Webdiyer.AspNetPager;
        pager.CurrentPageIndex = e.NewPageIndex;

    }
}
